package com.younion.business.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.younion.business.IAfficheService;
import com.younion.common.exception.BaseException;
import com.younion.common.paginator.Paginator;
import com.younion.dao.AfficheDAO;
import com.younion.vo.AfficheVO;

import cpcns.jhsks.util.MapCollectionUtils;
 
public class AfficheServiceImpl extends BaseService implements IAfficheService {
	
	protected static final Log logger = LogFactory.getLog(AfficheServiceImpl.class);
	
	private AfficheDAO afficheDAO;
	
	public List get(Map paramMap, Paginator paginator) throws BaseException {
		if (MapCollectionUtils.isEmpty(paramMap))
			return null;
		try {
			Map<String,Map> map = new HashMap<String,Map>();
			map.put("paramMap", paramMap);
			return this.afficheDAO.selectForPage(map, paginator);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(
					AfficheServiceImpl.class.getName()
							+ " >> public Page get(Map paramMap, Integer curPage, Integer pageSize) error occur:",
					e);
		}
	}

	public int getCountByMap(Map paramMap) throws BaseException {
		try {
			return this.afficheDAO.selectCountByMap(paramMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
					+ " >> public Collection getCountByMap(Map map) error occur:", e);
		}
	}

	public AfficheVO save(AfficheVO voObject) throws BaseException {
		if (voObject == null)
			return null;
		try {
			return (AfficheVO) this.afficheDAO.insertByVo(voObject);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
					+ " >> public AfficheVO save(AfficheVO voObject) error occur:", e);
		}
	}
	
	public boolean deleteAfficheById(Map paramMap) throws BaseException {
		try {
			return this.afficheDAO.deleteAfficheById(paramMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
					+ " >> public boolean deleteAfficheById(Map paramMap) error occur:", e);
		}
	}

	public boolean deleteAfficheByIds(List list) throws BaseException {
		try {
			return this.afficheDAO.deleteAfficheByIds(list);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
					+ " >> public boolean deleteAfficheByIds(List list) error occur:", e);
		}
	}

	public AfficheVO selectAfficheById(Map paramMap) throws BaseException {
		try {
			return this.afficheDAO.selectAfficheById(paramMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
					+ " >> public AfficheVO selectAfficheById(Map paramMap) error occur:", e);
		}
	}

	public boolean updateAfficheByMap(Map paramMap) throws BaseException {
		try {
			return this.afficheDAO.updateAfficheByMap(paramMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
					+ " >> public boolean updateAfficheByMap(Map paramMap) error occur:", e);
		}
	}
	
	public void setAfficheDAO(AfficheDAO afficheDAO) {
		this.afficheDAO = afficheDAO;
	}
	
	public AfficheDAO getAfficheDAO() {
		return this.afficheDAO;
	}

	public List selectWebAffiche(Map condition, Paginator paginator) throws BaseException {
		try {
			Map<String,Map> map = new HashMap<String,Map>();
			map.put("paramMap", condition);
			return this.afficheDAO.selectWebAffiche(map, paginator);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
							+ " >> public List selectWebAffiche(Map condition, Paginator paginator) error occur:", e);
		}
	}

	public List<AfficheVO> selectApiAfficheByMap(Map paramMap) throws BaseException {
		try {
			return this.afficheDAO.selectApiAfficheByMap(paramMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(AfficheServiceImpl.class.getName()
					+ " >> public AfficheVO selectAfficheById(Map paramMap) error occur:", e);
		}
	}
}
